package com.csnf.servlet;

import com.csnf.dao.IClaDao;
import com.csnf.dao.impl.ClaDaoImpl;
import com.csnf.entity.Cla;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet({"/getAllCla","/getAllClaToList","/getStudentByClaId"})
public class ClaServlet extends HttpServlet {
    IClaDao claDao = new ClaDaoImpl();
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String servletPath = request.getServletPath();
        switch (servletPath){
            case "/getAllCla":
                List<Cla> claList = claDao.findAll();
                request.setAttribute("claList", claList);
                request.getRequestDispatcher("addStudent.jsp").forward(request, response);
//                request.setAttribute("claList",claDao.findAll());
//                request.getRequestDispatcher("addStudent.jsp").forward(request,response);
                break;
            case "/getAllClaToList":
                request.setAttribute("claList",claDao.findAll());
                request.getRequestDispatcher("claList.jsp").forward(request,response);
                break;
            case "/getStudentByClaId":
                request.setAttribute("cla",claDao.findById(Integer.parseInt(request.getParameter("cId"))));
                request.getRequestDispatcher("claStudent.jsp").forward(request,response);
        }

    }

}
